package com.example.demo.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created on 2021/10/2.
 *
 * @author a1234
 */
public class AsyncUtils {

    private static final Integer coreSize = Runtime.getRuntime().availableProcessors();

    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(coreSize, coreSize, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(100));

    public static void invoke(Invoker invoker) {
        executor.execute(() -> invoker.invoke());
    }

    public interface Invoker {
        /**
         * invoke
         */
        void invoke();
    }
}
